| Conditions | 1 |
| Paths | 1 |
| Total Lines | 57 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | import chai from 'chai' |
||
| 17 | describe('cmsStructure', function() { |
||
| 18 | |||
| 19 | var folderPath = '/my/folder/path' |
||
| 20 | |||
| 21 | /** |
||
| 22 | * cmsStructure.structure.addFolder |
||
| 23 | * |
||
| 24 | */ |
||
| 25 | it('cmsStructure.structure.addFolder()', function() { |
||
| 26 | this.sinon = sinon.sandbox.create(); |
||
| 27 | //TODO: find how to stub function litteral "mkdirp" |
||
| 28 | // var stub = sinon.stub(mkdirp, "") |
||
| 29 | // var stub = sinon.createStubInstance(mkdirp); |
||
| 30 | |||
| 31 | // var result = cmsStructure.structure.addFolder(folderPath) |
||
| 32 | // chai.expect(result).to.not.be.undefined |
||
| 33 | // chai.expect(result).to.be.a('string') |
||
| 34 | // chai.expect(result).to.equal(folderPath) |
||
| 35 | // chai.expect(result).to.equal(path.join(config.root, config.publish.url, '/myImageFolder')) |
||
| 36 | // sinon.assert.calledOnce(mkdirp) |
||
| 37 | // mkdirp.restore() |
||
| 38 | }); |
||
| 39 | |||
| 40 | /** |
||
| 41 | * cmsStructure.structure.removeFolder |
||
| 42 | * |
||
| 43 | */ |
||
| 44 | it('cmsStructure.structure.removeFolder()', function() { |
||
| 45 | this.sinon = sinon.sandbox.create(); |
||
| 46 | var stub = sinon.stub(execPromise, "exec") |
||
| 47 | stub.returns(Promise.resolve({ |
||
| 48 | 'stdout': null, |
||
| 49 | 'stderr': null |
||
| 50 | })); |
||
| 51 | var result = cmsStructure.structure.removeFolder(folderPath) |
||
| 52 | chai.expect(result).to.not.be.undefined |
||
| 53 | chai.expect(result).to.equal(folderPath) |
||
| 54 | sinon.assert.calledOnce(execPromise.exec) |
||
| 55 | execPromise.exec.restore() |
||
| 56 | }); |
||
| 57 | |||
| 58 | /** |
||
| 59 | * cmsStructure.structure.editStructure |
||
| 60 | * |
||
| 61 | */ |
||
| 62 | it('cmsStructure.structure.editStructure()', function() { |
||
| 63 | this.sinon = sinon.sandbox.create(); |
||
| 64 | var stub = sinon.stub(cmsStructure.structure, "removeFolder") |
||
| 65 | stub.returns('') |
||
| 66 | var result = cmsStructure.structure.editStructure('remove', folderPath) |
||
| 67 | chai.expect(result).to.not.be.undefined |
||
| 68 | chai.expect(result).to.equal(folderPath) |
||
| 69 | sinon.assert.calledOnce(cmsStructure.structure.removeFolder) |
||
| 70 | cmsStructure.structure.removeFolder.restore() |
||
| 71 | }); |
||
| 72 | |||
| 73 | }); |
||
| 74 |